package com.wellsantos.dgwt.papelaria.client.view;

import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.googlecode.dgwt.client.dijit.form.Button;
import com.googlecode.dgwt.client.dijit.form.Label;
import com.googlecode.dgwt.client.dijit.form.TextBox;
import com.googlecode.dgwt.client.dijit.layout.HFlexPanel;
import com.googlecode.dgwt.client.dijit.layout.VFlexPanel;
import com.googlecode.dgwt.client.dojo.Dojo;
import com.wellsantos.dgwt.client.Action;
import com.wellsantos.dgwt.client.view.MenuViewBase;
import com.wellsantos.dgwt.papelaria.client.Papelaria;

public class MenuView extends BaseView implements MenuViewBase {


    private VerticalPanel menuPanel = new VerticalPanel();
    
    private SearchPanel searchPanel = new SearchPanel();
    
    
    public MenuView() {
        menuPanel.setWidth("180px");
        menuPanel.add(searchPanel.mainPanel);
        
        Button menuItem;
        
        for (Action action : Papelaria.getMenuActions()){
            
            menuItem = new Button(action.getLabel());
            menuItem.addClickHandler(action);
            menuPanel.add(menuItem);
        }
    }


    @Override
    public Widget getWidget() {
        return menuPanel;
    }

    
    @Override
    public Panel getContainerWidget() {
        return menuPanel;
    }


    class SearchPanel {
        
        private VFlexPanel mainPanel = new VFlexPanel();
        
        private HFlexPanel filterPanel = new HFlexPanel();
        
        private Label titlePanel = new Label(APPLICATION_RESOURCES.labelPesquisar());
        
        private TextBox inputBox = new TextBox();
        
        private Label promptLabel = new Label(APPLICATION_RESOURCES.labelPrompt()+":"/*, inputBox*/);
        
        private ListBox filterBox = new ListBox();
        
        private Button searchButton = new Button(APPLICATION_RESOURCES.btnOK());
                

        /**
         * cria o painel de pesquisa
         */
        public SearchPanel(){
            
            Papelaria.getTheme().searchPanel().applyTo(mainPanel, titlePanel);            
            
            mainPanel.setSize("100%", "auto");
            mainPanel.setSpacing(0);
            
            titlePanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
            titlePanel.setHeight("20px");
            
            inputBox.setWidth("100%");
            //promptLabel.setMarginTop("10px");
            searchButton.setMarginLeft("10px");
            
            filterPanel.add(filterBox, 1);
            filterPanel.add(searchButton);
            filterPanel.setMarginBottom("10px");
            
            mainPanel.add(titlePanel);
            mainPanel.add(promptLabel);
            mainPanel.add(inputBox);
            mainPanel.add(filterPanel);

            Dojo.addClass(mainPanel.getWidgetTd(titlePanel), "firstChild");
            Dojo.addClass(mainPanel.getWidgetTd(inputBox), "child");
            Dojo.addClass(mainPanel.getWidgetTd(promptLabel), "child");
            Dojo.addClass(mainPanel.getWidgetTd(filterPanel), "lastChild");
        }
        
    }
    
}
